﻿using LibraryMIS.UC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LibraryMIS
{
    public partial class MainForm : Form
    {
        int panelWidth = 210;
        bool isCollspased;
        public MainForm()
        {
            InitializeComponent();
            isCollspased = false;
            RealTime.Start();//启动timer事件

            MovePanelCourse(btnManageBook);
            ManageBooks mb = new ManageBooks();//实例化用户控件对象mb
            AddContainerToPanel(mb);
        }
        //将UC控件窗体填充至主要内容区域
        private void AddContainerToPanel(Control controlName)
        {
            controlName.Dock = DockStyle.Fill;
            panelModelContent.Controls.Clear();//清除主要内容区域的UC
            panelModelContent.Controls.Add(controlName);//添加UC至主要内容区域
        }

        #region 关机按钮实现：鼠标进入、鼠标离开、关闭系统
        private void pictureBoxClose_MouseEnter(object sender, EventArgs e)
        {
            pictureBoxClose.BackColor = Color.Red;
        }

        private void pictureBoxClose_MouseLeave(object sender, EventArgs e)
        {
            pictureBoxClose.BackColor = Color.White;
        }

        private void pictureBoxClose_Click(object sender, EventArgs e)
        {
            //this.Close();//关闭当前窗口
            //this.Dispose();//释放资源
            //Application.Exit();//消息终止
            System.Environment.Exit(0);//完全释放
        }
        #endregion

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (isCollspased)
            {
                panelLeft.Width = panelLeft.Width + 10;
                if (panelLeft.Width >= panelWidth)
                {
                    timer1.Stop();
                    isCollspased = false;
                    this.Refresh();
                }
            }
            else
            {
                panelLeft.Width = panelLeft.Width - 10;
                if (panelLeft.Width <= 50)
                {
                    timer1.Stop();
                    isCollspased = true;
                    this.Refresh();
                }
            }
        }

        private void pictureBoxMore_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void RealTime_Tick(object sender, EventArgs e)
        {
            DateTime realtime = DateTime.Now;//取当前时间
            labRealTime.Text = realtime.ToString("HH:MM:ss");
            //注意：需要在构造函数中进行该控件的启动（RealTime.Start()）
        }
        #region Panel的光标移动(panelCursor)
        private void MovePanelCourse(Control controlName)
        {
            panelCursor.Top = controlName.Top;
            panelCursor.Height = controlName.Height;
        }
        #endregion

        private void btnManageBook_Click(object sender, EventArgs e)
        {
            MovePanelCourse(btnManageBook);
            ManageBooks mb = new ManageBooks();//实例化用户控件对象mb
            AddContainerToPanel(mb);
        }

        private void btnBorrowBook_Click(object sender, EventArgs e)
        {
            MovePanelCourse(btnBorrowBook);
            BorrowBook b2 = new BorrowBook();//实例化用户控件对象
            AddContainerToPanel(b2);
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            MovePanelCourse(btnHome);
        }

        private void btnReturnBook_Click(object sender, EventArgs e)
        {
            MovePanelCourse(btnReturnBook);
        }

        private void btnRenewBook_Click(object sender, EventArgs e)
        {
            MovePanelCourse(btnRenewBook);
        }

        private void btnConfig_Click(object sender, EventArgs e)
        {
            MovePanelCourse(btnConfig);
        }

        private void btnUserManagement_Click(object sender, EventArgs e)
        {
            MovePanelCourse(btnUserManagement);
        }

        private void btnAboutUs_Click(object sender, EventArgs e)
        {
            MovePanelCourse(btnAboutUs);
            AboutUS us = new AboutUS();
            us.ShowDialog();
        }
    }
}
